package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.ht.medicaltreatment.bean.OrderListBean
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class OrderListModel : BaseViewModel() {
    companion object{
        const val IN = "0"
        const val OUT = "1"
    }
    //未完成
    fun getList(transportSign:String,onResult:(MutableList<OrderListBean>)->Unit,onError:(String)->Unit = {}){
        viewModelScope.launch {
            // 0 转入   1 转出
            val bean = mApi.getList(transportSign)
            when(bean){
                is ApiResult.Success -> onResult(bean.data.data!!)
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }

    //全部
    fun getAllList(transportSign:String,onResult:(MutableList<OrderListBean>)->Unit,onError:(String)->Unit = {}){
        viewModelScope.launch {
            // 0 转入   1 转出
            val bean = mApi.getAllList(transportSign)
            when(bean){
                is ApiResult.Success -> onResult(bean.data.data!!)
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }
}